<%-- 
    Document   : rollregister1
    Created on : 2019-7-11, 23:27:27
    Author     : dusin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>上传注册</title> 
        <link rel="stylesheet" type="text/css" href="../../js/jquery/themes/default/easyui.css">
        <link rel="stylesheet" type="text/css" href="../../js/jquery/themes/icon.css">
        <link rel="stylesheet" type="text/css" href="../../css/demo.css">        
        <script type="text/javascript" src="../../js/jquery/jquery-3.3.1.js"></script>
        <script type="text/javascript" src="../../js/jquery/jquery.easyui.min.js"></script>
        <script>
            $(function() {
                $("#upload").click(function() {
                    $("#imgWait").show();
                    var formData = new FormData();
                    var files = document.getElementById("file1");
                    formData.append("myfile", document.getElementById("file1").files[0]);
                    $.ajax({
                        url: "../../util/UploadExcelFile",
                        type: "POST",
                        data: formData,
                        /**
                         *必须false才会自动加上正确的Content-Type
                         */
                        contentType: false,
                        /**
                         * 必须false才会避开jQuery对 formdata 的默认处理
                         * XMLHttpRequest会对 formdata 进行正确的处理
                         */
                        processData: false,
                        success: function(data) {
                            if (data[0].status == true) { //目前只传一个文件
                                alert("上传成功！");

                            } else {
                                alert(data[0].msg);
                            }
                            $("#imgWait").hide();
                        },
                        error: function() {
                            alert("上传失败！");
                            $("#imgWait").hide();
                        }
                    });
                });
            });
            function change(_obj,t) {
            var tempFile = $("#file1");
           var value = tempFile.filebox('getValue');

                     // 取后缀名
                         var ext = value.substring(value.lastIndexOf(".") + 1).toLowerCase();
                         if (ext != 'xls') {
                                 if (ext != 'xlsx') {
                                             $.messager.alert("消息提示", "文件格式不对！请重新上传", "error");
                                             return;
                                 }
             
                         }

//取file

                 var file = $(_obj).context.ownerDocument.activeElement.files[0]

       

            }

        </script>
    </head>
    <body>
        <div style="margin:20px 0;"></div>
        <div class="easyui-panel" title="上传平时成绩记录表注册" style="width:600px;padding:30px 70px 50px 70px">

            <div style="margin-bottom:20px">
                <div>文件:</div>
                <input class="easyui-filebox" name="file1" id="file1"
                       data-options="prompt:'选中文件...',buttonText:'选择文件', accept:'application/vnd.ms-excel',onChange:function c(p){change(p,this)}" 
                       style="width:100%">
            </div>
            <img src="../../img/gif/wait.gif"  width="150" height="150"
                 style="display:none;margin:0px,0px,0px,20px" />
            <div>
                <a href="#" id="upload" class="easyui-linkbutton" style="width:100%">上传</a>
            </div>
        </div>
    </body>
</html>
